/*
 * FlightTicket.java
 *
 * This program demonstrates using a class to store, accept and
 * display information about an airline ticket.
 *
 
 */

package com.javacore.day3.booking;

/**
 * FlightTicket is a class to store, accept and display information about
 * an airline ticket.
 *
 * @author
 */
public class FlightTicket {
    
    /** Creates a new instance of FlightTicket */
    public FlightTicket() {
        
        departureDate = new Date();
        departureTime = new Time();
    }
    
    /**
     * Instance variable of type Date class to store
     * the departure date of a flight.
     */
    Date departureDate;
    
    /**
     * Instance variable of type Time class to store
     * the departure time of a flight.
     */
    Time departureTime;
    
    /**
     * Instance variable to store number of tickets to book.
     */
    byte noOfTickets;
    
    /**
     * Instance variable to store the price of ticket.
     */
    double price = 1000;
    
    /**
     * Instance variable to store the total price of tickets booked.
     */
    double totalPrice;
    
    /**
     * Instance variable to store the type of cabin.
     * This variable will hold the value 1(Business class),
     * 2(First class), or 3(Economy class).
     */
    byte typeOfCabin;
    
    /**
     * Method to display the date stored in instance variable departureDate.
     */
    void getDepartureDate() {
        System.out.println("Departure Date: " + departureDate.day + "/" +
                departureDate.month + "/" + departureDate.year);
    }
    
    /**
     * Method to set instance variable departureDate.
     * @param d parameter containing day of year
     * @param m parameter containing month of year
     * @param y parameter containing year
     */
    void setDepartureDate(byte d, byte m, short y) {
        departureDate.day = d;
        departureDate.month = m;
        departureDate.year = y;
    }
    
    /**
     * Method to display time stored in instance variable departureTime.
     */
    void getDepartureTime() {
        System.out.println("Departure Time: " + departureTime.hours + ":" +
                departureTime.minutes);
    }
    
    /**
     * Method to set the instance variable departureTime.
     * @param obj an object containing the departure time of flight
     */
    void setDepartureTime(Time obj) {
        departureTime.hours = obj.hours;
        departureTime.minutes = obj.minutes;
    }
    
    /**
     * Method to compute the total price of tickets booked.
     * The total price will be decided on the basis of number of tickets
     * and the type of cabin.
     *
     * @return the total price of the tickets booked
     */
    double getTotalPrice() {
        switch(typeOfCabin) {
            
            case 1:
                totalPrice = noOfTickets * (price * 3);
                break;
                
            case 2:
                totalPrice = noOfTickets * (price * 2);
                break;
                
            case 3:
                totalPrice = noOfTickets * price;
                break;
        }
        return totalPrice;
    }
    
    /**
     * Method to display all the information about the tickets booked.
     */
    void displayTicketInformation() {
        
        System.out.println("\nFollowing is the information about the ticket(s) booked: ");
        System.out.println("--------------------------------------------------------");
        
        getDepartureDate();
        getDepartureTime();
        
        System.out.println("Number of tickets: " + noOfTickets);
        System.out.print("Type of cabin: ");
        
        switch(typeOfCabin) {
            
            case 1:
                System.out.print("Business class");
                break;
                
            case 2:
                System.out.print("First class");
                break;
                
            case 3:
                System.out.print("Economy class");
                break;
        }
        System.out.printf("\nTotal cost of the ticket: $%.2f", getTotalPrice());
    }
    
}
